package top.maof.book.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.maof.book.model.Book;
import top.maof.book.result.Result;
import top.maof.book.search.Search;

import java.util.List;

@Controller
@RequestMapping("/search")
@ResponseBody
public class SearchController {
    @Autowired
    Search search;

    @GetMapping("/{keyword}")
    public Result search(@PathVariable String keyword) throws Exception {
        return Result.success(search.search(Book.class, keyword, 10));
    }

    @PostMapping("")
    public Result search(String key, Integer n) throws Exception {
        return Result.success(search.search(Book.class, key, n));
    }

    @RequestMapping("/prompt/{keyword}")
    public Result prompt(@PathVariable String keyword) throws Exception {
        List<String> prompt = search.prompt(Book.class, keyword, 10);
        return Result.success(prompt);
    }
}
